home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / lib / tcl / dist6.3 / doc / SetVar.man < prev    next >
Encoding:
Text File  |  1992-04-30  |  9.4 KB  |  332 lines

  1. '\"
  2. '\" Copyright 1989 Regents of the University of California
  3. '\" Permission to use, copy, modify, and distribute this
  4. '\" documentation for any purpose and without fee is hereby
  5. '\" granted, provided that this notice appears in all copies.
  6. '\" The University of California makes no representations about
  7. '\" the suitability of this material for any purpose.  It is
  8. '\" provided "as is" without express or implied warranty.
  9. '\" 
  10. '\" $Header: /user6/ouster/tcl/man/RCS/SetVar.man,v 1.9 92/03/28 14:21:12 ouster Exp $ SPRITE (Berkeley)
  11. '\" 
  12. .\" The definitions below are for supplemental macros used in Sprite
  13. .\" manual entries.
  14. .\"
  15. .\" .HS name section [date [version]]
  16. .\"    Replacement for .TH in other man pages.  See below for valid
  17. .\"    section names.
  18. .\"
  19. .\" .AP type name in/out [indent]
  20. .\"    Start paragraph describing an argument to a library procedure.
  21. .\"    type is type of argument (int, etc.), in/out is either "in", "out",
  22. .\"    or "in/out" to describe whether procedure reads or modifies arg,
  23. .\"    and indent is equivalent to second arg of .IP (shouldn't ever be
  24. .\"    needed;  use .AS below instead)
  25. .\"
  26. .\" .AS [type [name]]
  27. .\"    Give maximum sizes of arguments for setting tab stops.  Type and
  28. .\"    name are examples of largest possible arguments that will be passed
  29. .\"    to .AP later.  If args are omitted, default tab stops are used.
  30. .\"
  31. .\" .BS
  32. .\"    Start box enclosure.  From here until next .BE, everything will be
  33. .\"    enclosed in one large box.
  34. .\"
  35. .\" .BE
  36. .\"    End of box enclosure.
  37. .\"
  38. .\" .VS
  39. .\"    Begin vertical sidebar, for use in marking newly-changed parts
  40. .\"    of man pages.
  41. .\"
  42. .\" .VE
  43. .\"    End of vertical sidebar.
  44. .\"
  45. .\" .DS
  46. .\"    Begin an indented unfilled display.
  47. .\"
  48. .\" .DE
  49. .\"    End of indented unfilled display.
  50. .\"
  51. '    # Heading for Sprite man pages
  52. .de HS
  53. .if '\\$2'cmds'       .TH \\$1 1 \\$3 \\$4
  54. .if '\\$2'lib'        .TH \\$1 3 \\$3 \\$4
  55. .if '\\$2'tcl'        .TH \\$1 3 \\$3 \\$4
  56. .if '\\$2'tk'         .TH \\$1 3 \\$3 \\$4
  57. .if t .wh -1.3i ^B
  58. .nr ^l \\n(.l
  59. .ad b
  60. ..
  61. '    # Start an argument description
  62. .de AP
  63. .ie !"\\$4"" .TP \\$4
  64. .el \{\
  65. .   ie !"\\$2"" .TP \\n()Cu
  66. .   el          .TP 15
  67. .\}
  68. .ie !"\\$3"" \{\
  69. .ta \\n()Au \\n()Bu
  70. \&\\$1    \\fI\\$2\\fP    (\\$3)
  71. .\".b
  72. .\}
  73. .el \{\
  74. .br
  75. .ie !"\\$2"" \{\
  76. \&\\$1    \\fI\\$2\\fP
  77. .\}
  78. .el \{\
  79. \&\\fI\\$1\\fP
  80. .\}
  81. .\}
  82. ..
  83. '    # define tabbing values for .AP
  84. .de AS
  85. .nr )A 10n
  86. .if !"\\$1"" .nr )A \\w'\\$1'u+3n
  87. .nr )B \\n()Au+15n
  88. .\"
  89. .if !"\\$2"" .nr )B \\w'\\$2'u+\\n()Au+3n
  90. .nr )C \\n()Bu+\\w'(in/out)'u+2n
  91. ..
  92. '    # BS - start boxed text
  93. '    # ^y = starting y location
  94. '    # ^b = 1
  95. .de BS
  96. .br
  97. .mk ^y
  98. .nr ^b 1u
  99. .if n .nf
  100. .if n .ti 0
  101. .if n \l'\\n(.lu\(ul'
  102. .if n .fi
  103. ..
  104. '    # BE - end boxed text (draw box now)
  105. .de BE
  106. .nf
  107. .ti 0
  108. .mk ^t
  109. .ie n \l'\\n(^lu\(ul'
  110. .el \{\
  111. .\"    Draw four-sided box normally, but don't draw top of
  112. .\"    box if the box started on an earlier page.
  113. .ie !\\n(^b-1 \{\
  114. \h'-1.5n'\L'|\\n(^yu-1v'\l'\\n(^lu+3n\(ul'\L'\\n(^tu+1v-\\n(^yu'\l'|0u-1.5n\(ul'
  115. .\}
  116. .el \}\
  117. \h'-1.5n'\L'|\\n(^yu-1v'\h'\\n(^lu+3n'\L'\\n(^tu+1v-\\n(^yu'\l'|0u-1.5n\(ul'
  118. .\}
  119. .\}
  120. .fi
  121. .br
  122. .nr ^b 0
  123. ..
  124. '    # VS - start vertical sidebar
  125. '    # ^Y = starting y location
  126. '    # ^v = 1 (for troff;  for nroff this doesn't matter)
  127. .de VS
  128. .mk ^Y
  129. .ie n 'mc \s12\(br\s0
  130. .el .nr ^v 1u
  131. ..
  132. '    # VE - end of vertical sidebar
  133. .de VE
  134. .ie n 'mc
  135. .el \{\
  136. .ev 2
  137. .nf
  138. .ti 0
  139. .mk ^t
  140. \h'|\\n(^lu+3n'\L'|\\n(^Yu-1v\(bv'\v'\\n(^tu+1v-\\n(^Yu'\h'-|\\n(^lu+3n'
  141. .sp -1
  142. .fi
  143. .ev
  144. .\}
  145. .nr ^v 0
  146. ..
  147. '    # Special macro to handle page bottom:  finish off current
  148. '    # box/sidebar if in box/sidebar mode, then invoked standard
  149. '    # page bottom macro.
  150. .de ^B
  151. .ev 2
  152. 'ti 0
  153. 'nf
  154. .mk ^t
  155. .if \\n(^b \{\
  156. .\"    Draw three-sided box if this is the box's first page,
  157. .\"    draw two sides but no top otherwise.
  158. .ie !\\n(^b-1 \h'-1.5n'\L'|\\n(^yu-1v'\l'\\n(^lu+3n\(ul'\L'\\n(^tu+1v-\\n(^yu'\h'|0u'\c
  159. .el \h'-1.5n'\L'|\\n(^yu-1v'\h'\\n(^lu+3n'\L'\\n(^tu+1v-\\n(^yu'\h'|0u'\c
  160. .\}
  161. .if \\n(^v \{\
  162. .nr ^x \\n(^tu+1v-\\n(^Yu
  163. \kx\h'-\\nxu'\h'|\\n(^lu+3n'\ky\L'-\\n(^xu'\v'\\n(^xu'\h'|0u'\c
  164. .\}
  165. .bp
  166. 'fi
  167. .ev
  168. .if \\n(^b \{\
  169. .mk ^y
  170. .nr ^b 2
  171. .\}
  172. .if \\n(^v \{\
  173. .mk ^Y
  174. .\}
  175. ..
  176. '    # DS - begin display
  177. .de DS
  178. .RS
  179. .nf
  180. .sp
  181. ..
  182. '    # DE - end display
  183. .de DE
  184. .fi
  185. .RE
  186. .sp .5
  187. ..
  188. .HS Tcl_SetVar tcl
  189. .BS
  190. .VS
  191. .SH NAME
  192. Tcl_SetVar, Tcl_SetVar2, Tcl_GetVar, Tcl_GetVar2, Tcl_UnsetVar, Tcl_UnsetVar2 \- manipulate Tcl variables
  193. .SH SYNOPSIS
  194. .nf
  195. \fB#include <tcl.h>\fR
  196. .sp
  197. char *
  198. \fBTcl_SetVar\fR(\fIinterp, varName, newValue, flags\fR)
  199. .sp
  200. char *
  201. \fBTcl_SetVar2\fR(\fIinterp, name1, name2, newValue, flags\fR)
  202. .sp
  203. char *
  204. \fBTcl_GetVar\fR(\fIinterp, varName, flags\fR)
  205. .sp
  206. char *
  207. \fBTcl_GetVar2\fR(\fIinterp, name1, name2, flags\fR)
  208. .sp
  209. int
  210. \fBTcl_UnsetVar\fR(\fIinterp, varName, flags\fR)
  211. .sp
  212. int
  213. \fBTcl_UnsetVar2\fR(\fIinterp, name1, name2, flags\fR)
  214. .SH ARGUMENTS
  215. .AS Tcl_Interp *newValue
  216. .AP Tcl_Interp *interp in
  217. Interpreter containing variable.
  218. .AP char *varName in
  219. Name of variable.  May refer to a scalar variable or an element of
  220. an array variable.
  221. .AP char *newValue in
  222. New value for variable.
  223. .AP int flags in
  224. OR-ed combination of bits providing additional information for
  225. operation. See below for valid values.
  226. .AP char *name1 in
  227. Name of scalar variable, or name of array variable if \fIname2\fR
  228. is non-NULL.
  229. .AP char *name2 in
  230. If non-NULL, gives name of element within array and \fIname1\fR
  231. must refer to an array variable.
  232. .BE
  233.  
  234. .SH DESCRIPTION
  235. .PP
  236. These procedures may be used to create, modify, read, and delete
  237. Tcl variables from C code.
  238. \fBTcl_SetVar\fR and \fBTcl_SetVar2\fR will create a new variable
  239. or modify an existing one.
  240. Both of these procedures set the given variable to the value
  241. given by \fInewValue\fR, and they return a pointer to a
  242. copy of the variable's new value, which is stored in Tcl's
  243. variable structure.
  244. Tcl keeps a private copy of the variable's value, so the caller
  245. may change \fInewValue\fR after these procedures return without
  246. affecting the value of the variable.
  247. If an error occurs in setting the variable (e.g. an array
  248. variable is referenced without giving an index into the array),
  249. then NULL is returned.
  250. .PP
  251. The name of the variable may be specified in either of two ways.
  252. If \fBTcl_SetVar\fR is called, the variable name is given as
  253. a single string, \fIvarName\fR.
  254. If \fIvarName\fR contains an open parenthesis and ends with a
  255. close parenthesis, then the value between the parentheses is
  256. treated as an index (which can have any string value) and
  257. the characters before the first open
  258. parenthesis are treated as the name of an array variable.
  259. If \fIvarName\fR doesn't have parentheses as described above, then
  260. the entire string is treated as the name of a scalar variable.
  261. If \fBTcl_SetVar2\fR is called, then the array name and index
  262. have been separated by the caller into two separate strings,
  263. \fIname1\fR and \fIname2\fR respectively;  if \fIname2\fR is
  264. zero it means that a scalar variable is being referenced.
  265. .PP
  266. The \fIflags\fR argument may be used to specify any of several
  267. options to the procedures.
  268. It consists of an OR-ed combination of any of the following
  269. bits:
  270. .IP TCL_GLOBAL_ONLY
  271. Under normal circumstances the procedures look up variables
  272. at the current level of procedure call for \fIinterp\fR, or
  273. at global level if there is no call active.
  274. However, if this bit is set in \fIflags\fR then the variable
  275. is looked up at global level even if there is a procedure
  276. call active.
  277. .IP TCL_LEAVE_ERR_MSG
  278. If an error is returned and this bit is set in \fIflags\fR, then
  279. an error message will be left in \fI\%interp->result\fR.  If this
  280. flag bit isn't set then no error message is left (\fI\%interp->result\fR
  281. will not be modified).
  282. .IP TCL_APPEND_VALUE
  283. If this bit is set then \fInewValue\fR is appended to the current
  284. value, instead of replacing it.
  285. If the variable is currently undefined, then this bit is ignored.
  286. .IP TCL_LIST_ELEMENT
  287. If this bit is set, then \fInewValue\fR is converted to a valid
  288. Tcl list element before setting (or appending to) the variable.
  289. If the list element is being appended to an non-empty value, then
  290. a space character is appended before the new list element to
  291. separate it from previous elements.
  292. .IP TCL_NO_SPACE
  293. If this bit is set, it prevents the output of a separating space
  294. character in TCL_LIST_ELEMENT appends.
  295. This bit has no effect if the TCL_LIST_ELEMENT bit isn't set.
  296. .PP
  297. \fBTcl_GetVar\fR and \fBTcl_GetVar2\fR return the current value
  298. of a variable.
  299. The arguments to these procedures are treated in the same way
  300. as the arguments to \fBTcl_SetVar\fR and \fBTcl_SetVar2\fR.
  301. Under normal circumstances, the return value is a pointer
  302. to the variable's value (which is stored in Tcl's variable
  303. structure and will not change before the next call to \fBTcl_SetVar\fR
  304. or \fBTcl_SetVar2\fR).
  305. The only bits of \fIflags\fR that are used are TCL_GLOBAL_ONLY
  306. and TCL_LEAVE_ERR_MSG, both of
  307. which have
  308. the same meaning as for \fBTcl_SetVar\fR.
  309. If an error occurs in reading the variable (e.g. the variable
  310. doesn't exist or an array element is specified for a scalar
  311. variable), then NULL is returned.
  312. .PP
  313. \fBTcl_UnsetVar\fR and \fBTcl_UnsetVar2\fR may be used to remove
  314. a variable, so that future calls to \fBTcl_GetVar\fR or \fBTcl_GetVar2\fR
  315. for the variable will return an error.
  316. The arguments to these procedures are treated in the same way
  317. as the arguments to \fBTcl_GetVar\fR and \fBTcl_GetVar2\fR.
  318. If the variable is successfully removed then 0 is returned.
  319. If the variable cannot be removed because it doesn't exist
  320. or because a trace is active for it, then -1 is returned.
  321. If an array element is specified, the given element is removed
  322. but the array remains.
  323. If an array name is specified without an index, then the entire
  324. array is removed.
  325.  
  326. .SH "SEE ALSO"
  327. Tcl_TraceVar
  328.  
  329. .SH KEYWORDS
  330. array, interpreter, scalar, set, unset, variable
  331. .VE
  332.